﻿using System;
using System.Web.Mvc;
using PTop.Application.Biz;
using PTop.Code;
using PTop.Code.Excel;
using PTop.Domain.Entity.Biz;

namespace PTop.Web.Areas.Biz.Controllers
{
    /// <summary>
    /// 工作应聘Controller
    /// </summary>	
    public class JobCandidateController : ControllerBase
    {
        private JobCandidateApp _app = new JobCandidateApp();

        [HttpGet]
        [HandlerAjaxOnly]
        public ActionResult GetGridJson(Pagination pagination, string pid, string keyword, int state)
        {
            var data = _app.GetList(pagination, pid, keyword, state);
            return PageContent(pagination.records, pagination.rows, data);
        }
        [HttpGet]
        [HandlerAjaxOnly]
        public ActionResult GetFormJson(string keyValue)
        {
            var data = _app.GetForm(keyValue);
            return Content(data.ToJson());
        }
        [HttpPost]
        [HandlerAjaxOnly]
        [ValidateAntiForgeryToken]
        public ActionResult SubmitForm(JobCandidateEntity entity, string keyValue)
        {
            _app.SubmitForm(entity, keyValue);
            return Success("操作成功。");
        }
        [HttpPost]
        [HandlerAjaxOnly]
        [HandlerAuthorize]
        [ValidateAntiForgeryToken]
        public ActionResult DeleteForm(string keyValue)
        {
            _app.Delete(keyValue);
            return Success("删除成功。");
        }

        /// <summary>
        /// 下载统计结果
        /// </summary>
        /// <param name="pid"></param>
        /// <param name="state"></param>
        /// <returns></returns>
        [HandlerAuthorize]
        public ActionResult Download(string pid, int state)
        {
            var pagination = new Pagination
            {
                page = 1,
                rows = 100000,
                sidx = "F_CreatorTime desc",
                sord = "asc"
            };
            var list = _app.GetList(pagination, pid, null, state);
            new ExcelExportHelper<JobCandidateEntity>(list)
               .AddProperty(m => m.F_JobTitle, "工作")
               .AddProperty(m => m.F_Name, "姓名")
               .AddProperty(m => m.F_Gender, "性别")
               .AddProperty(m => m.F_Age, "年龄")
               .AddProperty(m => m.F_Phone, "电话")
               .AddProperty(m => m.F_Address, "地址")
               .AddProperty(m => m.F_Salary, "期望薪水")
               .AddProperty(m => m.F_State, "处理状态", JobCandidateEntity.GetStateName)
               .AddProperty(m => m.F_CreatorTime, "时间")
               .ToExcel("应聘信息导出-" + DateTime.Now.ToString("yyyyMMddhh"));
            return new EmptyResult();
        }

    }
}